<PageHeader as |p|>
  <p.top>
    <KeyValueHeader @baseKey={{baseKey}} @path="vault.cluster.access.leases.list" @root={{backendCrumb}} @showCurrent={{true}} @linkToPaths={{capabilities.leases.canList}} />
  </p.top>
  <p.levelLeft>
    <h1 class="title is-3">
      <LinkTo @route="vault.cluster.access.leases">
        Leases
      </LinkTo>
    </h1>
  </p.levelLeft>
</PageHeader>

{{#if capabilities.revoke.canUpdate}}
  <Toolbar>
    <ToolbarActions>
      <ConfirmAction
        @buttonClasses="toolbar-link"
        @confirmTitle="Revoke this?"
        @confirmMessage={{concat "All leases under this one will also be removed"}}
        @confirmButtonText="Confirm"
        @onConfirmAction={{action "revokeLease" model}}
        data-test-lease-revoke="true"
      >
        Revoke lease
      </ConfirmAction>
    </ToolbarActions>
  </Toolbar>
{{/if}}

<div class="field box is-fullwidth is-sideless is-paddingless is-marginless">
  <InfoTableRow @label="Issue time" @value={{model.issueTime}}>
    {{date-format model.issueTime 'MMM dd, yyyy hh:mm:ss a'}}
    <br/>
    <code>
      {{model.issueTime}}
    </code>
  </InfoTableRow>
  <InfoTableRow @label="Renewable" @value={{model.renewable}} />
  <InfoTableRow @label="Last renewal" @value={{model.lastRenewal}}>
    {{date-format model.lastRenewal 'MMM dd, yyyy hh:mm:ss a'}}
    <br/>
    <code>
      {{model.lastRenewal}}
    </code>
  </InfoTableRow>
  {{#if model.expireTime}}
    <InfoTableRow @label="Expiration time" @value={{model.expireTime}}>
      {{date-format model.expireTime 'MMM dd, yyyy hh:mm:ss a'}}
      <br/>
      <code>
        {{model.expireTime}}
      </code>
    </InfoTableRow>
    <InfoTableRow @label="Expires in" @value={{date-from-now model.expireTime increment=1000 hideSuffix=true}} />
  {{/if}}
  <InfoTableRow @label="TTL" @value={{model.ttl}} />
</div>
{{#if (and (not model.isAuthLease) model.renewable capabilities.renew.canUpdate)}}
  <div class="box is-shadowless" data-test-lease-renew-picker=true>
    <h2 class="title is-6">Renew Lease</h2>
    <form {{action "renewLease" model increment on="submit"}}>
      <TtlPicker2 
        @label="Increment"
        @helperTextEnabled="Lease will expire after" 
        @helperTextDisabled="Vault will use the default lease duration" 
        @labelClass="is-label" 
        @onChange={{action (mut increment)}} @unit="s" 
      />
      <div class="field has-top-margin-s">
        <div class="control">
          <button
            type="submit"
            class="button is-primary"
          >
            Renew lease
          </button>
        </div>
      </div>
    </form>
  </div>
{{/if}}
